<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="货物类型" prop="gtype">
        <el-input
          v-model="queryParams.gtype"
          placeholder="请输入货物类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['commodity:commodity:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="listCategory"></right-toolbar>
    </el-row>

    <el-table :row-class-name="tableRowClassName" v-loading="loading" :data="Data" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="货物id" align="center" prop="goods.gid" />-->
      <el-table-column label="货物类别" align="center" prop="goods.gtype" />
      <el-table-column label="商品数量" align="center" prop="ccount" />
    </el-table>

<!--    <pagination-->
<!--      v-show="total>0"-->
<!--      :total="total"-->
<!--      :page.sync="queryParams.pageNum"-->
<!--      :limit.sync="queryParams.pageSize"-->
<!--      @pagination="listCategory"-->
<!--    />-->


  </div>
</template>

<script>
import { getCategorys } from "@/api/commodity/commodity";
//import { getGoodsList} from "@/api/goods/goods";

export default {
  // name: "Commodity",
  data() {
    return {
      dataTable: [],
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品信息表格数据
      commodityList: [],
      //货物列表
      goodsList: [],
      //货物类别列表
      categoryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      Data:[],


      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        gname: '',
      },
      // 表单参数
      commodity: {
        goods: {
          gid: null,
        }
      },

    };
  },
  created() {
    //this.getList();
    //this.getGoods();

    this.listCategory();
  },
  methods: {

    //指定行颜色
    tableRowClassName: function({ row, rowIndex }) {
      console.log(row, 'row');
      console.log("rowIndex", rowIndex);
      if (row.ccount > 3) {
        return 'rowbg';
      }
    },

    listCategory() {
      this.loading = true;
      let params = {};
      if (this.queryParams.cname) {
        params.goods = { gname: this.queryParams.cname };
      }
      getCategorys(params).then(response => {
        // alert(JSON.stringify(response))
        this.Data = response.rows; // 更新数据列表
        this.total = response.total; // 更新总条数
        this.loading = false;
        // alert(JSON.stringify(response))
      }).catch(error => {
        console.error('获取数据失败：', error);
        this.loading = false;
      });
    },

    // /** 查询商品信息列表 */
    // getList() {
    //   this.loading = true;
    //   listCommodity(this.queryParams).then(response => {
    //     this.commodityList = response.rows;
    //     this.total = response.total;
    //     this.loading = false;
    //   });
    // },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.commodity = {
        cid: null,
        ccount: null,
        goods: {
          gid: null,
        },
        deleted: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.listCategory();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.cid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },


    /** 导出按钮操作 */
    handleExport() {
      this.download('commodity/commodity/export', {
        ...this.queryParams
      }, `commodity_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style>
.rowbg{
  background: rgba(255, 254, 192, 0.65) !important;
}
</style>
